package cn.cmkj.auction.data.http;

import org.json.JSONArray;
import org.json.JSONObject;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by cunguoyao on 2017/9/24.
 */

public class Address implements Serializable {

    private String id;
    private String area;
    private String name;
    private String addr;
    private String zip;
    private String telphone;
    private String email;
    private String r_time;
    private String mobile;

    private boolean isDefault;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getArea() {
        return area;
    }

    public void setArea(String area) {
        this.area = area;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAddr() {
        return addr;
    }

    public void setAddr(String addr) {
        this.addr = addr;
    }

    public String getZip() {
        return zip;
    }

    public void setZip(String zip) {
        this.zip = zip;
    }

    public String getTelphone() {
        return telphone;
    }

    public void setTelphone(String telphone) {
        this.telphone = telphone;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getR_time() {
        return r_time;
    }

    public void setR_time(String r_time) {
        this.r_time = r_time;
    }

    public String getMobile() {
        return mobile;
    }

    public void setMobile(String mobile) {
        this.mobile = mobile;
    }

    public boolean isDefault() {
        return isDefault;
    }

    public void setDefault(boolean aDefault) {
        isDefault = aDefault;
    }

    public static Address parseFromJson(JSONObject json){
        if(json != null) {
            Address address = new Address();
            address.setAddr(json.optString("addr"));
            address.setArea(json.optString("area"));
            address.setEmail(json.optString("email"));
            address.setMobile(json.optString("mobile"));
            address.setName(json.optString("name"));
            address.setR_time(json.optString("r_time"));
            address.setTelphone(json.optString("telephone"));
            address.setZip(json.optString("zip"));
            return address;
        }
        return null;
    }

    public static List<Address> parseJsonArray(JSONArray array) {
        List<Address> list = new ArrayList<>();
        if(array != null && array.length() > 0){
            for(int i=0;i<array.length();i++){
                list.add(parseFromJsonForList(array.optJSONObject(i)));
            }
        }
        return list;
    }

    public static Address parseFromJsonForList(JSONObject json){
        if(json != null) {
            Address address = new Address();
            address.setId(json.optString("ship_id"));
            address.setAddr(json.optString("ship_addr"));
            address.setArea(json.optString("ship_area"));
            address.setEmail(json.optString("ship_email"));
            address.setMobile(json.optString("ship_mobile"));
            address.setName(json.optString("ship_name"));
            address.setTelphone(json.optString("ship_tel"));
            address.setZip(json.optString("ship_zip"));
            address.setDefault(json.optBoolean("is_default"));
            return address;
        }
        return null;
    }
}
